package cn.test.util;

import java.util.Random;

public class GeneralRandom {
	public static String getRandomString(int length) {
		String str = "abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ0123456789";
		Random random = new Random();
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < length; i++) {
			int number = random.nextInt(62);
			sb.append(str.charAt(number));
		}
		return sb.toString();
	}

	public static String getRandomString2(int length) {

		Random random = new Random();
		StringBuffer sb = new StringBuffer();

		int number = 0;
		long result = 0;
		for (int i = 0; i < length; i++) {
			number = random.nextInt(3);
			switch (number) {
			case 0:
				result = Math.round(Math.random() * 25 + 65);
				sb.append(String.valueOf((char) result));
				break;
			case 1:
				result = Math.round(Math.random() * 25 + 97);
				sb.append(String.valueOf((char) result));
				break;
			case 2:
				result = random.nextInt(10);
				sb.append(String.valueOf(result));
				break;
			}
		}
		return sb.toString();

	}

	public static void main(String[] args) {
		System.out.print(getRandomString2(10));
	}

}
